package com.metal.silver.controller;

import com.ruoyi.common.utils.ServletUtils;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.metal.meta.service.form.FormDataService;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.metal.silver.domain.CustomerMarket;
import com.metal.silver.service.ICustomerMarketService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户营销单Controller
 * 
 * @author Kelvin
 * @date 2022-10-20
 */
@Controller
@RequestMapping("/silver/market2")
public class CustomerMarketController2 extends BaseController
{
    private String prefix = "silver/market";

    @Autowired
    private ICustomerMarketService customerMarketService;

    @RequiresPermissions("silver:market:view")
    @GetMapping()
    public String market()
    {
        return prefix + "/market";
    }

    /**
     * 查询客户营销单列表
     */
    @RequiresPermissions("silver:market:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CustomerMarket customerMarket)
    {
        return FormDataService.list(customerMarket);
    }

    /**
     * 导出客户营销单列表
     */
    @RequiresPermissions("silver:market:export")
    @Log(title = "客户营销单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CustomerMarket customerMarket)
    {
        List<CustomerMarket> list = customerMarketService.selectCustomerMarketList(customerMarket);
        ExcelUtil<CustomerMarket> util = new ExcelUtil<CustomerMarket>(CustomerMarket.class);
        return util.exportExcel(list, "客户营销单数据");
    }

    /**
     * 新增客户营销单
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存客户营销单
     */
    @RequiresPermissions("silver:market:add")
    @Log(title = "客户营销单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CustomerMarket customerMarket)
    {
        return toAjax(FormDataService.addSave(customerMarket));
    }

    /**
     * 修改客户营销单
     */
    @RequiresPermissions("silver:market:edit")
    @GetMapping("/edit/{uuid}")
    public String edit(@PathVariable("uuid") String uuid, ModelMap mmap)  throws ClassNotFoundException
    {
        String domainName = "customerMarket";
        String fullName = "com.metal.silver.domain." + StrUtil.upperFirst(domainName);
        Class clazz = Class.forName(fullName);
        JSONObject dbJsonObj = FormDataService.selectByUuid(ServletUtils.getParameter("domain"), uuid);
        mmap.put("customerMarket", JSONObject.toJavaObject(dbJsonObj, clazz));
        return prefix + "/edit";
    }

    /**
     * 修改保存客户营销单
     */
    @RequiresPermissions("silver:market:edit")
    @Log(title = "客户营销单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CustomerMarket customerMarket)
    {
        return toAjax(FormDataService.editSave( customerMarket));
    }

    /**
     * 删除客户营销单
     */
    @RequiresPermissions("silver:market:remove")
    @Log(title = "客户营销单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(customerMarketService.deleteCustomerMarketByUuids(ids));
    }
}
